package com.unionServer.common;

import java.util.Properties;

/**
 * @description:
 * @author: wangxinal
 * @time: 2022/1/18 8:48
 */
public class MetaDataDataType {
    private String name;
    public static final MetaDataDataType STRING = new MetaDataDataType("string");
    public static final MetaDataDataType INT = new MetaDataDataType("int");
    public static final MetaDataDataType DOUBLE = new MetaDataDataType("double");
    public static final MetaDataDataType SHORT = new MetaDataDataType("short");
    public static final MetaDataDataType FLOAT = new MetaDataDataType("float");
    public static final MetaDataDataType LONG = new MetaDataDataType("long");
    public static final MetaDataDataType BYTE = new MetaDataDataType("byte");
    public static final MetaDataDataType IMAGE = new MetaDataDataType("image");
    public static final MetaDataDataType DATE = new MetaDataDataType("date");
    public static final MetaDataDataType CHAR = new MetaDataDataType("char");
    private Properties pro;

    public MetaDataDataType(String var1) {
        this.name = "";
        this.pro = new Properties();
        if (var1 != null && var1.length() > 0) {
            this.name = var1;
        } else {
            throw new IllegalArgumentException("The name of metadata type  must not be empty");
        }
    }

    public MetaDataDataType(String var1, Properties var2) {
        this(var1);
        this.pro = var2;
    }

    public Properties getAttrs() {
        return this.pro;
    }

    public int getLength() {
        int var1 = Integer.parseInt(this.getProperty("length"));
        return var1;
    }

    public String getProperty(String var1) {
        String var2 = this.pro.getProperty(var1);
        var2 = var2 != null && var2.trim().length() >= 0 ? var2 : "-1";
        return var2;
    }

    public int getScale() {
        return Integer.parseInt(this.pro.getProperty("scale"));
    }

    public static boolean integerType(MetaDataDataType var0) {
        return var0.equals(LONG) || var0.equals(INT) || var0.equals(SHORT) || var0 == BYTE;
    }

    public static boolean decimalType(MetaDataDataType var0) {
        return var0.equals(DOUBLE) || var0.equals(FLOAT);
    }

    public static boolean stringType(MetaDataDataType var0) {
        return var0 == STRING;
    }

    public static boolean numberType(MetaDataDataType var0) {
        return integerType(var0) || decimalType(var0);
    }

    public static MetaDataDataType getType(String var0) {
        if (var0.equals("string")) {
            return STRING;
        } else if (var0.equals("image")) {
            return IMAGE;
        } else if (var0.equals("byte")) {
            return BYTE;
        } else if (var0.equals("short")) {
            return SHORT;
        } else if (var0.equals("int")) {
            return INT;
        } else if (var0.equals("long")) {
            return LONG;
        } else if (var0.equals("float")) {
            return FLOAT;
        } else {
            return var0.equals("double") ? DOUBLE : null;
        }
    }

    public boolean equals(MetaDataDataType var1) {
        return this.name.equalsIgnoreCase(var1.name);
    }
}
